<?php
/**
 * Created by PhpStorm.
 * User: Da Xiong
 * Date: 2018/12/7
 * Time: 16:45
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Models\Mall;
use App\Models\MallOrders;

class OrderController extends Controller
{

    /**
     * 获取订单列表
     */
    public function index(){
        $params = [
            'oid' => (string)request('oid',''),
            'status' => (int)request('status',0),
        ];
        $list = MallOrders::where(function($query) use($params){
                if ($params['oid']){
                    $query->where('oid',$params['oid']);
                }
                if ($params['status'] > 0){
                    $query->where('status',$params['status']);
                }
            })
            ->with('shop')
            ->orderBy('id','DESC')
            ->paginate(20);
        $this->stateToText($list,[
            'status' => MallOrders::STATUS_TEXT,
        ]);
        return $this->returnJson(0,'',$list);
    }

    /**
     * 更新订单信息
     */
    public function update(){
        $data = request()->all();

        if(!isset($data['id'])){
            $data['id'] = 0;
        }

        if ($data['id'] > 0){
            //编辑
            $info = MallOrders::find($data['id']);
            if(!$info){
                return $this->returnJson(1, '数据不存在');
            }
            $info->update($data);
            return $this->returnJson(0, '发货成功');
        }
        return $this->returnJson(1,'error');
    }
}